﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Core
{
    public static partial class problem
    {
        public static dynamic getProblemStatistics(int pid)
        {
            var sql = new Sql.SqlDataContext();
            if (!sql.Problem.Any(row => row.pid == pid)) return new
                {
                    success = false,
                    msg = "题目不存在"
                };
            var ps = sql.ProblemStatistics.FirstOrDefault(row => row.pid == pid);
            if (ps == null) ps = new Sql.ProblemStatistics();

            var usub = sql.Solve.Count(row => row.pid == pid && row.submit > 0);
            var uac = sql.Solve.Count(row => row.pid == pid && row.accept > 0);

            var result = new List<statistics>();
            result.Add(new statistics(20, "Total Submissions", ps.submit));
            result.Add(new statistics(3, "Accepted", ps.accept));
            result.Add(new statistics(21, "Users Submitted", usub));
            result.Add(new statistics(22, "Users Solved", uac));
            result.Add(new statistics(4, "Presentation Error", ps.pe));
            result.Add(new statistics(5, "Time Limit Exceeded", ps.tle));
            result.Add(new statistics(6, "Memory Limit Exceeded", ps.mle));
            result.Add(new statistics(7, "Output Limit Exceeded", ps.ole));
            result.Add(new statistics(8, "Wrong Answer", ps.wa));
            result.Add(new statistics(9, "Runtime Error", ps.re));
            result.Add(new statistics(10, "Compile Error", ps.ce));
            result.Add(new statistics(11, "System Error", ps.se));
            return new
            {
                success = true,
                result
            };
        }
    }
}
